home *** CD-ROM | disk | FTP | other *** search
- { errmsg.pas -- Display error messages from a string table }
-
- program ErrMsg;
-
- {$R errmsg.res}
-
- uses WinTypes, WinProcs, WObjects, Strings;
-
- const
-
- id_Menu = 100; { Menu resource ID }
- cm_Op = 101; { Command IDs }
- cm_Quit = 102;
-
- maxErrorNumber = 6; { Top error number in string table }
-
- type
-
- ErrMsgApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PErrMsgWindow = ^ErrMsgWindow;
- ErrMsgWindow = object(TWindow)
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure CMOp(var Msg: TMessage);
- virtual cm_First + cm_Op;
- procedure CMQuit(var Msg: TMessage);
- virtual cm_First + cm_Quit;
- end;
-
-
- { ErrMsgApplication }
-
- {- Initialize ErrMsgApplication object's window }
- procedure ErrMsgApplication.InitMainWindow;
- begin
- MainWindow := New(PErrMsgWindow, Init(nil, 'ErrMsg'))
- end;
-
-
- { ErrMsgWindow }
-
- {- Construct ErrMsgWindow object }
- constructor ErrMsgWindow.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- Attr.Menu := LoadMenu(HInstance, PChar(id_Menu));
- end;
-
- {- Display error message; return true to cancel failed operation }
- function ErrorCancel(HWindow: HWnd; ErrNum: Word): Boolean;
- var
- S3: String[3];
- ErrCap: array[0 .. 11] of Char;
- ErrStr: array[0 .. 63] of Char;
- begin
- Str(ErrNum, S3);
- StrPCopy(ErrCap, 'Error #:' + S3);
- if LoadString(HInstance, ErrNum, ErrStr, 63) > 0 then
- ErrorCancel :=
- MessageBox(HWindow, ErrStr, ErrCap,
- mb_IconStop or mb_RetryCancel) = idCancel
- else
- ErrorCancel := true
- end;
-
- {- Execute pseudo operation }
- procedure ErrMsgWindow.CMOp(var Msg: TMessage);
- var
- ErrNum: Word;
- Canceled: Boolean;
- begin
- Canceled := true; { Present "done" flag }
- repeat
- ErrNum := 1 + Random(maxErrorNumber); { Simulate error }
- if ErrNum <> 0 then
- Canceled := ErrorCancel(HWindow, ErrNum)
- until Canceled
- end;
-
- {- Exit program }
- procedure ErrMsgWindow.CMQuit(var Msg: TMessage);
- begin
- CloseWindow
- end;
-
- var
-
- ErrMsgApp: ErrMsgApplication;
-
- begin
- ErrMsgApp.Init('ErrMsgApp');
- ErrMsgApp.Run;
- ErrMsgApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 4/16/1991
- ---------------------------------------------------------------}
-